import { _decorator, sp, Sprite } from 'cc';
import { BaseUI } from '../../framework/base/BaseUI';
import { BaseEventName } from '../../framework/config/Appcfg';
import { AudioMgr } from '../../framework/manager/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('UILoad')
export class UILoad extends BaseUI {
    @property(Sprite)
    SpBar: Sprite = null;

    //是否加载完成
    isLoadFinish: boolean = false;

    //当前进度值
    curProgressValue: number = 30;


    /**难度飙升 */
    @property(sp.Skeleton)
    loadAni: sp.Skeleton = null;

    start() {
        AudioMgr.getInstance().stopMusic("MainBGM");
        // console.log("开始加载")
        this.addEvent(BaseEventName.CloseUI, this.onCloseUI)
        this.registerEvent();
        this.refreshProcessBar();
   
        // this.scheduleOnce(() => {
        //     this.closeUI();
        // }, 0.5);
        this.loadAni.timeScale = 1.3
        this.loadAni.setAnimation(0, 'animation', false)
        this.loadAni.setCompleteListener(() => {
            this.isLoadFinish = true;
            this.closeUI();
        })
    }

    refreshProcessBar() {
        // console.log("扯淡ne: ", this.SpBar)
        this.SpBar.fillRange = this.curProgressValue / 100;
    }

    registerEvent() {
        //关卡加载完成事件
        // this.addEvent(EventName.LoadLevelFinish, this.loadLevelFinish);
    }

    loadLevelFinish() {
        // this.curProgressValue += 35;
        // console.log("进度加载值：", this.curProgressValue);
        this.refreshProcessBar();
        if (this.curProgressValue >= 100) {
            this.isLoadFinish = true;
            this.closeUI();
        }
    }


    onCloseUI(uid: any, msg: string) {

    }
}

